#include <iostream>
#include <pthread.h>
#include <signal.h>
#include <unistd.h>
#include "errno.h"
#include <stdio.h>

void *thfunc(void *arg)
{
    int tm=50;
    while (1)
    {
        std::cout << "th left"<<tm << "s--"<<std::endl;
        sleep(1);
        tm--;
    }
    return (void*)0;
}

int main()
{
    pthread_t pid;
    int res;
    pthread_create(&pid,NULL,thfunc,NULL);
    sleep(5);
    int kill_rc=pthread_kill(pid,0); // 探测子线程是否存活
    if (kill_rc==ESRCH)
    {
        std::cout<<"not exist or quit" << std::endl;
    }
    else if(kill_rc==EINVAL)
    {
        printf("signal is invalid\n");
    }
    else
    {
        printf("thread is alive\n");
    }
    return 0;
    
}